/*
 * @Author: zehao.chen
 * @Date: 2022-07-10 11:03:30
 * @LastEditors: zehao.chen
 * @LastEditTime: 2022-08-30 16:43:20
 * @FilePath: /meeting-admin/src/main.js
 * @Description:
 *
 */
import Vue from 'vue'
import Cookies from 'js-cookie'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import moment from 'moment'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import enLang from 'element-ui/lib/locale/lang/en' // lang i18n
import '@/styles/index.scss' // global css
import format from '@/utils/format'
import 'amfe-flexible/index.js'


import App from './App'
import store from './store'
import router from './router'
import qs from 'qs'

import '@/icons' // icon
import '@/permission' // permission control
import { getDicts, getSupplierDicts } from "@/api/dict";
import VueDragResize from 'vue-drag-resize'
Vue.component('vue-drag-resize', VueDragResize)
import WarnPanelDialog from "@/components/WarnPanelDialog";
Vue.component('WarnPanelDialog', WarnPanelDialog)
import FileGroupManager from "@/components/fileGroupManager";
Vue.component('FileGroupManager', FileGroupManager)
import FileContentSearchHeader from "@/components/FileContentSearchHeader";
Vue.component('FileContentSearchHeader', FileContentSearchHeader)
import EditFileInfo from "@/components/EditFileInfo";
Vue.component('EditFileInfo', EditFileInfo)
import EditProgramInfo from "@/components/EditProgramInfo";
Vue.component('EditProgramInfo', EditProgramInfo)
import TerListDialog from "@/components/TerListDialog";
Vue.component('TerListDialog', TerListDialog)
// eventbus
Vue.prototype.$bus = new Vue()
Vue.prototype.$moment = moment

// 视频播放 vue-video-player
import VueVideoPlayer from 'vue-video-player'
// require videojs style
import 'video.js/dist/video-js.css'
// import 'vue-video-player/src/custom-theme.css'

Vue.use(VueVideoPlayer /* {
  options: global default options,
  events: global videojs events
} */)

// import VCalendar from "v-calendar"; // 引入日曆插件

// Vue.use(VCalendar, {
//   componentPrefix: "vc",
// });

import CommonTable from '@/components/Table/commonTable'//  通用表格组件
Vue.component(
  'CommonTable',
  CommonTable
)

import htmlToPdf from '@/utils/htmlToPdf'
Vue.use(htmlToPdf)

Vue.directive('clearForm', {
  bind: (el, binding) => {
    el.addEventListener('click', (ev) => {
      const formModel = binding.value
      Object.keys(binding.value).forEach((item) => {
        if (item !== 'pageNum' && item !== 'pageSize') {
          binding.value[item] = ''
        }
      })
    })
  }
})
/**
 * 如果您不想使用模拟服务器
 * 你想用MockJs来模拟api可以执行:mockXHR()
 * 目前MockJs将用于生产环境，
 * 请在上线前删除!!!
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, {
//   size: Cookies.get('size') || 'medium', // set element-ui default size
//   locale: enLang // 如果使用中文，无需设置，请删除
// })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.prototype.$qs = qs
Vue.prototype.$local = window.localStorage
Vue.prototype.getDicts = getDicts
Vue.prototype.getSupplierDicts = getSupplierDicts

// false 生产环境 ,true 开发环境
Vue.config.productionTip = true

// const OSS = require('ali-oss')
// const client = new OSS({
//   region: 'oss-cn-guangzhou',
//   accessKeyId: 'LTAI5tNryQ3jq1BrBgT1N3NP',
//   accessKeySecret: '8V63aooLcATW7SdQxAcpOVKQDxBgrL',
//   bucket: 'zhenxiaohuiyi'
// })

const ossOtherSCJTUpload = (file) => {
  return new Promise((resolve, reject) => {
    const files = file.file;
    imageOssUploadMethods(files)
      .then((res) => {
        resolve(res);
      })
      .catch(() => {
        reject();
      });
  });
}

const imageOssUploadMethods = async (file) => {
  let listTmp = file.name.split('.')
  const fileType = file.name.split('.')[listTmp.length - 1]
  const uploadUrl = `upload/${format(new Date().getTime(), 'YYYY-MM')}/${new Date().getTime()}.${fileType}`
  // 填写Object完整路径。Object完整路径中不能包含Bucket名称。
  // 您可以通过自定义文件名（例如exampleobject.txt）或目录（例如exampledir/exampleobject.txt）的形式，实现将文件上传到当前Bucket或Bucket中的指定目录。
  let result = {}

  console.log('fileType ---', fileType)
  if (fileType === 'pdf') {
    result = await client.multipartUpload(uploadUrl, file, {
      progress: (p, checkpoint, res) => {
        // checkpoint参数用于记录上传进度，断点续传上传时将记录的checkpoint参数传入即可。浏览器重启后无法直接继续上传，您需要手动触发上传操作。
        // this.tempCheckpoint = checkpoint
      },
      parallel: 4,
      // 设置分片大小。默认值为1 MB，最小值为100 KB。
      partSize: 1024 * 1024,
      mime: 'application/x-pcx'
    })
  } else {
    result = await client.multipartUpload(uploadUrl, file, {
      progress: (p, checkpoint, res) => {
        // checkpoint参数用于记录上传进度，断点续传上传时将记录的checkpoint参数传入即可。浏览器重启后无法直接继续上传，您需要手动触发上传操作。
        // this.tempCheckpoint = checkpoint
      },
      parallel: 4,
      // 设置分片大小。默认值为1 MB，最小值为100 KB。
      partSize: 1024 * 1024,
      mime: 'text/plain'
    })
  }
  // this.$message.success('上传成功')
  return result
}

// import Rem from "./utils/rem";
// Rem.setFontSize();


Vue.prototype.$ossOtherSCJTUpload = ossOtherSCJTUpload


new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App),
})
